<template>
	<view class="content">
		<!-- 动态绑定list高度 -->
		<scroll-view class="list" scroll-y="true" @scrolltolower="getMore" v-if="isShow">
			<view class="listItem" v-for="(item,index) in association" :key="index"
				@click="$navto.navto('/packageB/association_info/association_info',{id:item.community_id})">
				<image :src="item.communityBe.head" class="avatar"></image>
				<text class="name">{{item.communityBe.name}}</text>
				<text class="info"
					v-if="item.activity_time">成员{{item.community_user_num}}人&ensp;&ensp;/&ensp;&ensp;近期活动：{{$timestampToTime(item.activity_time)}}</text>
				<text class="info" v-else>成员{{item.community_user_num}}人&ensp;&ensp;/&ensp;&ensp;新社群</text>
				<view class="join" v-if="item.status==1" @click.stop="exit(item.community_id,index)">
					退出
				</view>
				<view class="exit" v-if="item.check_status==0">
					审核中
				</view>
				<view class="exit" v-if="item.check_status==2">
					已拒绝
				</view>
				<view class="line" v-if="index!=association.length-1">
				</view>
			</view>
		</scroll-view>
		<view class="noBox" v-else>
			<image :src="baseurl+'associationAdd/18.png'" class="noIcon" />
			<text class="noLabel">您还暂未加入社群</text>
			<view class="joinBtn" @click="$navto.navto('/packageB/association/association')">
				加入社群
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				baseurl: this.$baseurl,
				association: [],
				page: 1,
				isShow: true
			}
		},
		onLoad(options) {
			this.getData();
		},
		methods: {
			// 退出社群
			exit(id,index) {
				uni.showModal({
					title: '提示',
					content: '是否确认退出',
					success: (res) => {
						if (res.confirm) {
							this.$request.post(`CommunityUser/community_user`, {
								community_id: id
							}).then(res => {
								console.log(res);
								this.$u.toast('退出成功');
								this.association.splice(index, 1);
							});
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
			},
			getMore() {
				this.page++;
				this.getData();
			},
			// 获取社群列表数据
			getData() {
				this.$request.get(`communityUser/my_join?page=${this.page}`).then(res => {
					this.association.push(...res.data.data);
					if (this.association.length == 0) {
						this.isShow = false;
					}
				})
			},
		}
	}
</script>

<style lang="scss">
	.noBox {
		width: 100%;
		height: 100%;
		display: flex;
		flex-direction: column;
		align-items: center;

		.joinBtn {
			width: 346rpx;
			height: 90rpx;
			line-height: 90rpx;
			text-align: center;
			background-color: #4E97AD;
			border-radius: 45rpx;
			color: #fff;
			margin-top: 70rpx;
			font-size: 28rpx;
			font-weight: 500;
		}

		.noLabel {
			width: 100%;
			text-align: center;
			font-size: 28rpx;
			font-weight: 500;
			color: #919191;
			margin-top: 80rpx;
		}

		.noIcon {
			width: 76rpx;
			height: 76rpx;
			margin-top: 350rpx;
		}
	}

	.list {
		width: 670rpx;
		height: 100vh;
		margin-left: 40rpx;
		overflow-y: scroll;
		padding-top: 20rpx;
	}

	.list .listItem {
		width: 100%;
		height: 160rpx;
		position: relative;
		display: flex;
		justify-content: space-between;
		margin-top: 70rpx;

		.line {
			position: absolute;
			right: 0;
			bottom: 0;
			width: 530rpx;
			height: 2rpx;
			background-color: #d8d8d8;
		}

		.exit {
			position: absolute;
			top: 0;
			right: 0;
			width: 136rpx;
			height: 60rpx;
			border-radius: 30rpx;
			text-align: center;
			line-height: 60rpx;
			font-size: 22rpx;
			font-weight: 500;
			// background-color: #D95945;
			color: #D95945;
		}

		.join {
			position: absolute;
			top: 0;
			right: 0;
			width: 136rpx;
			height: 60rpx;
			border-radius: 30rpx;
			text-align: center;
			line-height: 60rpx;
			font-size: 22rpx;
			font-weight: 500;
			background-color: #D95945;
			color: #fff;
		}

		.info {
			position: absolute;
			font-size: 24rpx;
			font-weight: 500;
			top: 65rpx;
			left: 145rpx;
			color: #919191;
		}

		.name {
			position: absolute;
			font-size: 32rpx;
			font-weight: 700;
			top: 10rpx;
			left: 145rpx;
		}

		.avatar {
			width: 100rpx;
			height: 100rpx;
			border-radius: 50%;
		}
	}

	.content {
		width: 100%;
		height: 100%;
		background-color: #fff;
		background: url('https://miantou.guguan.net/img/common/bg.png');
		background-size: 100% auto;
	}

	page {
		width: 100%;
		height: 100%;
		background-color: #fff;
	}
</style>